<?php

namespace App\Api\Controllers;

use App\Api\Dao\OrderDao;
use App\Api\Logic\OrderLogic;
use App\Exceptions\DaoException;
use App\Exceptions\ValidationException;
use App\Helpers\Lib\WechatPay;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;

class NoticeController extends BaseController
{
    /**
     * 微信支付通知
     * @return void
     */
    public function weCahtPayNotice(){

    }

    /**
     * 钱包支付
     * @return \Illuminate\Http\JsonResponse
     * @throws ValidationException
     * @throws DaoException
     */
    public function payNotice(Request $request,OrderLogic $orderLogic,OrderDao $orderDao)
    {
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $orderLogic->pagNotice($params);
        $result = $orderDao->payNotice($params);
        return $this->success($result);
    }

    /**
     * @param Request $request
     * @param OrderLogic $orderLogic
     * @param OrderDao $orderDao
     * @return \Illuminate\Http\JsonResponse
     * @throws DaoException
     * @throws ValidationException
     */
    public function payRepeatMoneyNotice(Request $request,OrderLogic $orderLogic,OrderDao $orderDao)
    {
        $params = $request->all();
        $params = array_merge(['u_id'=>$request->u_id],$params);
        $orderLogic->pagNotice($params);
        $result = $orderDao->payRepeatMoneyNotice($params);
        return $this->success($result);
    }



    /**
     * 微信支付回调
     * @return void
     */
    public function wechatPayNotice(Request $request){
        $data = $request->all();
        Log::info('微信支付回调',$data);
        (new WechatPay())->wechatPayNotice($data);
    }

    /**
     * 用户充值回调
     * @return void
     */
    public function wechatRechargeNotice(){
        Log::info('微信支付充值回调');
        (new WechatPay())->wechatRechargeNotice();
    }

    public function wechatRefundOrder(){
        Log::info('微信退款回调');
        (new WechatPay())->wechatRefundOrder();
    }
}
